//
//  LFShoppingCartViewController.m
//  LoveFreshBee
//
//  Created by 王忠迪 on 10/15/16.
//  Copyright © 2016 王忠迪. All rights reserved.
//

#import "LFShoppingCartViewController.h"
#import "DVShoppingViewModel.h"
#import "DVShoppingModel.h"
#import "Masonry.h"

#define KgotoShopping  @"KgotoShopping"
@interface LFShoppingCartViewController ()
@property(nonatomic,weak)UIImageView* imgV;
@property(nonatomic,weak)UIButton* btn;
@property(nonatomic,weak)UILabel* lable;
@end



@implementation LFShoppingCartViewController

-(UIImageView*)imgV{
    
    
    if (!_imgV) {
        
        UIImageView* i = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"v2_shop_empty"]];
        
        _imgV = i;
        
        [self.view addSubview:_imgV];
        
    }
    
    return  _imgV;
}


-(UIButton*)btn{
    
    if (!_btn) {
        
        UIButton* b = [UIButton new];
        
        _btn = b;
        
        [b setTitle: DVShoppingViewModel.shared.shoppingModel.empty_btn_text forState:UIControlStateNormal];
        
        [b setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        
        [b  setBackgroundImage:[UIImage imageNamed:@"btn.png"] forState:UIControlStateNormal];
        
        [b sizeToFit];
        
        [b addTarget:self action:@selector(emtpyBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:_btn];

    }
    
    return _btn;
}





-(UILabel*)lable{
    
    if (!_lable) {
        
        UILabel * i = [UILabel new];
        
        i.text = DVShoppingViewModel.shared.shoppingModel.empty_text;
        
        i.textColor = [UIColor darkGrayColor];
        
        [i sizeToFit];
        
        _lable = i;
        
        [self.view addSubview:_lable];
    }
    
    return _lable;
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupUI];
}


- (void)setupUI {
    
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelBtnClick)];
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"v2_goback"] style:UIBarButtonItemStyleDone target:self action:@selector(cancelBtnClick)];
    
    self.navigationItem.title = DVShoppingViewModel.shared.shoppingModel.controller_title;
    
    
    
    [self.lable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imgV.mas_bottom).offset(20);
        make.centerX.equalTo(self.view);
    }];
    
    
    [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.centerY.equalTo(self.view).offset(-100);
    }];
    
    
    [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lable.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(self.btn.bounds.size.width+40, self.btn.bounds.size.height));
          make.centerX.equalTo(self.view);
    }];
    
    
    
}


-(void)emtpyBtnDidClick{
    
    [[NSNotificationCenter defaultCenter]postNotificationName:KgotoShopping object:nil userInfo:nil];
    
    [self cancelBtnClick];
    
    
    
}

- (void)cancelBtnClick {
    
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
